package cn.regexp.business.web.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.regexp.common.base.page.TablePageInfo;
import cn.regexp.domain.ShopConsignee;
import cn.regexp.query.ConsigneeQuery;
import cn.regexp.service.IConsigneeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 轮播图控制器
 */
@Controller
@RequestMapping("business/consignees")
public class ConsigneeController {
    //模板前缀
    private static final String prefix = "business/consignees/";

    @Autowired
    private IConsigneeService consigneesService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:consignees:view")
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }


    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:consignees:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<ShopConsignee> query(ConsigneeQuery qo){
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        QueryWrapper<ShopConsignee> wrapper = new QueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(qo.getKeyword()), "username", qo.getKeyword())
                .or()
                .like(ObjectUtil.isNotEmpty(qo.getKeyword()), "consignee_name", qo.getKeyword())
                .like(ObjectUtil.isNotEmpty(qo.getConsigneeMobile()), "consignee_mobile", qo.getConsigneeMobile());
        return new TablePageInfo<>(consigneesService.list(wrapper), consigneesService.count(wrapper));
    }

}
